package com.zis.auction.web;

import com.alibaba.fastjson.JSONObject;
import com.zis.auction.model.AuctOrg;
import com.zis.auction.service.IAuctOrgInter;
import com.zis.auction.service.ICarouselInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Create by wangshen 2018/1/10
 */
@RestController
@RequestMapping("/api/open/auction/index")
public class AuctIndexRestful {

    @Autowired
    private ICarouselInter carouselInter;

    @Autowired
    private IAuctOrgInter auctOrgInter;

    /**
     * 获取首页图片
     * @return
     */
    @RequestMapping(value = "/images", method = RequestMethod.GET)
    @ResponseBody
    public List<JSONObject> findThreeItem() {
        return carouselInter.findThreeItem();
    }


    /**
     * 查询推荐企业
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/recom/org", method = RequestMethod.GET)
    @ResponseBody
    public List<JSONObject> recomOrg() throws Exception {
        return auctOrgInter.findRecom();
    }

    /**
     * 企业信息查看
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/org/view/{id}", method = RequestMethod.GET)
    @ResponseBody
    public JSONObject recomView(@PathVariable("id") String id) throws Exception {
        AuctOrg auctOrg = auctOrgInter.selectById(id);
        if (auctOrg != null) {
            JSONObject dataJSON = new JSONObject();
            dataJSON.put("orgName", auctOrg.getOrgName());
            dataJSON.put("orgIntro", auctOrg.getOrgIntro());
            dataJSON.put("orgId", auctOrg.getAuoId());
            return dataJSON;
        }
        return null;
    }
}
